#!/bin/bash

# clone tools project

apt update && apt install git -y
git clone https://gitee.com/youclk/tools.git 

cd tools/ubuntu && python3 setting.py
rm -r tools

# add dns
echo -e "\nnameserver 8.8.8.8 \nnameserver 114.114.114.114"  >> /etc/resolv.conf

# add swap

fallocate -l 4G /swapfile 
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

free -m

echo -e "\n/swapfile none swap sw 0 0"  >> /etc/fstab

# add crontab task
echo -e  "\n* */1 * * * root docker rm \`docker ps -aq\` | docker rmi \`docker images | egrep 'youclk|none' | awk '{print \$3}'\` \`docker images | egrep 'youclk|none' | awk '{OFS=\":\";print \$1,\$2}'\` | docker volume rm \`docker volume ls -q\`" >>  /etc/crontab

# install aliyun control
sudo bash -c "wget -O /tmp/cloudmonitor.tar.gz 'http://cms-download.aliyun.com/release/1.2.11/linux64/agent-linux64-1.2.11-package.tar.gz' && \
mkdir /usr/local/cloudmonitor && \
tar -xf  /tmp/cloudmonitor.tar.gz -C /usr/local/cloudmonitor && \
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh install && \
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh start"

apt install nfs-common -y

# install docker 

apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt -y update
apt -y install docker-ce

# add registry-mirrors

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://jrzzvzok.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

# install docker compose
curl -L https://gitee.com/youclk/entry/raw/master/compose/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

docker login --username=youclk@qq.com registry-vpc.cn-hangzhou.aliyuncs.com
